home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_09
/
8n09026a
< prev
next >
Wrap
Text File
|
1990-07-28
|
686b
|
36 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUMELEM(a) (sizeof(a)/sizeof(a[0]))
main()
{
int cmpstra(const void *, const void *);
char *array[] = {"abc", "Xy", "1234", "Abc", "xyz"};
int i;
qsort(&array[0], NUMELEM(array), sizeof(char *), cmpstra);
printf("ascending string order\n");
for (i = 0; i < NUMELEM(array); ++i)
printf("array[%d] = %s\n", i, array[i]);
return 0;
}
/* compare strings in ascending order */
int cmpstra(const void *pe1, const void *pe2)
{
return strcmp(*(char **)pe1, *(char **)pe2);
}
ascending string order
array[0] = 1234
array[1] = Abc
array[2] = Xy
array[3] = abc
array[4] = xyz